 

# # 配置路径
# png_dir = "FY2025052966465088_output_images_GZ/"
# output_pdf = "FY2025052966465088_output.pdf"
  
import os
import img2pdf

png_dir = "你的PNG文件夹/"
output_pdf = "output.pdf"


# # 配置路径
png_dir = "FY2025052966465088_output_images_GZ/"
output_pdf = "FY2025052966465088_output.pdf"

# 获取所有PNG并按数字排序
png_files = sorted(
    [os.path.join(png_dir, f) for f in os.listdir(png_dir) if f.endswith('.png')],
    key=lambda x: int(x.split('_')[-1].replace('.png', ''))
)

# 转换为PDF
with open(output_pdf, "wb") as f:
    f.write(img2pdf.convert(png_files))

print(f"PDF 已生成: {output_pdf}")